package com.yanqu.road.server.cmd.activity.wishpool;

import com.yanqu.road.pb.activity.WishPoolProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.wishpool.WishPoolModule;
import com.yanqu.road.server.manger.activity.wishpool.WishPoolMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_ACTIVITY_WISH_POOL_DATA, desc = "获取许愿池数据")
public class GetWishPoolDataCmd extends AbstractCommand {

    private WishPoolProto.WishPoolDataMsg.Builder wishPoolDataMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (!WishPoolMgr.isActivityInShowTime()) {
            ret = GameErrorCode.E_ACTIVITY_WISH_POOL_NOT_IN_TIME;
            return;
        }

        WishPoolModule wishPoolModule = player.getModule(WishPoolModule.class);
        wishPoolDataMsg = wishPoolModule.getWishPoolDataMsg();
    }

    @Override
    public void sendData(GamePlayer player) {
        WishPoolProto.GetWishPoolDataRespMsg.Builder respMsg = WishPoolProto.GetWishPoolDataRespMsg.newBuilder();
        respMsg.setRet(ret);
        if (ret == 0) {
            respMsg.setWishPoolData(wishPoolDataMsg);
        }
        player.sendPacket(ClientProtocol.U_ACTIVITY_WISH_POOL_DATA, respMsg);
    }
}
